﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//=====================================================================================/
/// <summary>
/// 绑定在状态机状态上
/// </summary>
//=====================================================================================.
public partial class AnimatorState : StateMachineBehaviour
{
    private AnimatorStateController m_Controller = null;

    private bool m_IsInited = false;

    public AnimatorStateController Controller(Animator animator)
    {
        if (!m_IsInited)
        {
            m_Controller = animator.transform.GetComponent<AnimatorStateController>();
            m_IsInited = true;
        }
        return m_Controller;
    }

    /// <summary>
    /// 状态开始
    /// </summary>
    /// <param name="animator"></param>
    /// <param name="stateInfo"></param>
    /// <param name="layerIndex"></param>
    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateEnter(animator, stateInfo, layerIndex);
        if (Controller(animator) != null)
        {
            m_Controller.StateEnter(animator, stateInfo, layerIndex);
        }
    }

    /// <summary>
    /// 状态结束
    /// </summary>
    /// <param name="animator"></param>
    /// <param name="stateInfo"></param>
    /// <param name="layerIndex"></param>
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateExit(animator, stateInfo, layerIndex);
        if (Controller(animator) != null)
        {
            m_Controller.StateExit(animator, stateInfo, layerIndex);
        }
    }
}